-- signboard_award
-- created by zhuangsl
-- 冈布奥事件：月卡领奖

-- 确认月卡领奖的事件
EventMgr.register("signboard_award", event.UI_TAKE_SUPERIOR_BONUS, function(para)
    -- 有领奖概率
    if not SuperiorM.canTakeExtraBonus() then
        return;
    end

    local level = para.level;

    local arr = SlimeEventM.getIdsByRule("signboard_award");
    local num = #arr;

    local eventInfo = {};
    local sum = 0;

    -- 提取有用信息，准备抽取事件
    for i = 1, num do
        local id = arr[i];
        local dbase = SlimeEventM.query(id, "dbase");

        eventInfo[i] = {
                ["id"] = id,
                ["ratio"] = dbase["ratio"],
                ["pet_id"] = dbase["pet_id"],
                ["bonus_type"] = dbase["bonus_type"],
            };

        -- 1级月卡不给钻，3级月卡不给金币，特殊处理下
        if level == 1 then
            if dbase["bonus_type"] == "gem" then
                eventInfo[i]["ratio"] = 0;
            elseif dbase["bonus_type"] == "money" then
                eventInfo[i]["ratio"] = eventInfo[i]["ratio"] * 2;
            end
        end

        if level == 3 then
            if dbase["bonus_type"] == "gem" then
                eventInfo[i]["ratio"] = eventInfo[i]["ratio"] * 2;
            elseif dbase["bonus_type"] == "money" then
                eventInfo[i]["ratio"] = 0;
            end
        end

        sum = sum + eventInfo[i]["ratio"];
    end

    -- 抽取一个事件
    local rand = RandomFactoryM.myRandom(ME.user) % sum;
    sum = 0;
    for i = 1, num do
        sum = sum + eventInfo[i]["ratio"];
        if sum > rand then
            -- 抽中了，若有指定宠物，则触发奖励事件
            local petId = eventInfo[i]["pet_id"];
            if not ME.user.pets[petId] then
                break;
            else
                SlimeEventM.triggerEvent(eventInfo[i]["id"], {["level"] = level, ["bonus_type"] = eventInfo[i]["bonus_type"], });
                break;
            end
        end
    end
end);

return {
};
